package com.first.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.first.common.pojo.EduCourse;
import com.first.course.mapper.EduCourseMapper;
import com.first.course.service.EduCourseService;
import com.first.course.vo.EduCourseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;


/**
 * @program: first-project
 * @description:
 * @author: 路志欣
 * @create: 2023-05-26 15:52
 **/
@Service
public class EduCourseServiceImpl implements EduCourseService {
    @Autowired
    private EduCourseMapper eduCourseMapper;


    /**
     *
     * @param pageCurrent
     * @param pageSize
     * @param eduCourseVo
     * @return 分页模糊查询
     */
    @Override
    public Page<EduCourse> findCourse(Integer pageCurrent, Integer pageSize, EduCourseVo eduCourseVo) {
        Page<EduCourse> page = new Page<>(pageCurrent,pageSize);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
       if(StringUtils.hasText(eduCourseVo.getTitle())){
           wrapper.like("c.title",eduCourseVo.getTitle());
       }
        if (StringUtils.hasText(eduCourseVo.getStatus())){
            wrapper.eq("status",eduCourseVo.getStatus());
        }
        wrapper.eq("cc.check_status",1);
        Page<EduCourse> page1 = eduCourseMapper.findByConditionPage(page, wrapper);
        return page1;
    }

    /**
     *
     * @param id
     * @param status
     * @return 修改上下架状态
     */
    @Override
    public Integer updateStatus(String id, String status) {
        EduCourse eduCourse = new EduCourse();
        eduCourse.setId(id);
        eduCourse.setStatus(status);
        eduCourse.setGmtModified(LocalDateTime.now());
        int updateStatus = eduCourseMapper.updateById(eduCourse);
        return updateStatus;
    }

    @Override
    public Integer updateCourseDescription(EduCourse eduCourse) {
        Integer integer = eduCourseMapper.updateCourseDescription(eduCourse);
        return integer;
    }


}
